<!DOCTYPE html>
<html lang="en">
<head>
    {template 'common/edithead'}
    <!--微擎 -->
    <!--这个放在最后一切平白安全-->
    <script type="text/javascript" src="./resource/js/require.js?v=20170915"></script>
    <script type="text/javascript">
        //编辑器里使用
        var urobj=[];
    </script>
</head>
<body class="nav-md" style="min-width: 800px">
<div>
    <div class="container xc_edit_from" >
        <div class="main_container" style="overflow-x: hidden;min-height: calc(100vh - 20px);background-color: white;width: 100%;">
            <div class="col-md-12 col-xs-12">
                <div class="x_panel">
                    <ul class="we7-page-tab">
                        <li >
                            <a  href="{php echo $this->createWebUrl($do, array('op'=>'list','xtitleb'=>urlencode($xtitleb),'xtitlea'=>urlencode($xtitlea),'new'=>1));}">
                                {$xtitleb}- {$xtitlea}列表  </a></li>
                        <li><a a href="{php echo $this->createWebUrl($do, array('op'=>'edit','xtitleb'=>urlencode($xtitleb),'xtitlea'=>urlencode($xtitlea),'new'=>1));}">{$xtitleb}- {$xtitlea}增加</a></li>
                    </ul>
                    <div class="x_content">
                        <br/>
                        <form id="sign-form" class="form-horizontal" role="form" method="post" name="submit">
                            <div style="display: none;">
                                {php echo tpl_form_field_image('wwww');}
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">课程</label>
                                <div class="col-sm-8">
                                    <select  class="form-control js-select2" name="pid" data-select="{$list['pid']}">
                                        <option value="">请选择课程</option>
                                        {loop $class $index $item}
                                        <option value="{$item['id']}" {if $item['id']==$list['pid']}selected{/if} >{$item['name']}</option>
                                        {/loop}
                                    </select>
                                    <input type="hidden" name="id" value="{$list['id']}">
                                    <input type="hidden" name="link">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">标识</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="mark" value="{$list['mark']}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">截止时间</label>
                                <div class="col-sm-8">
                                    {php echo tpl_form_field_date('end_time',$list['end_time'],true);}
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">名额</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="member" value="{$list['member']}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">参与人数</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="join_member" value="{$list['join_member']}">
                                    <span class="help-block">虚拟人数</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">价格</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="price" value="{$list['price']}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">最低价格</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="cut_price" value="{$list['cut_price']}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">砍价区间</label>
                                <div class="col-sm-8">
                                    <div class="input-group">
                                        <input type="text" class="form-control" name="min_price" value="{$list['min_price']}">
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="button">至</button>
                        </span>
                                        <input type="text" class="form-control" name="max_price" value="{$list['max_price']}">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">虚拟人数</label>
                                <div class="col-sm-8">
                                    {if $list['link']}
                                    {loop $list['link'] $index $item}
                                    <div class="input-group param">
                                        <input type="text" name="simg" value="{$item['simg']}" class="form-control" autocomplete="off">
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="button" onclick="showImageDialog(this);">头像</button>
                        </span>
                                        <input type="text" name="nick" value="{$item['nick']}" class="form-control" placeholder="昵称" style="width: 33.333%;">
                                        <input type="text" name="number" value="{$item['number']}" class="form-control" placeholder="数量" style="width:  33.333%;">
                                        <input type="text" name="content" value="{$item['content']}" class="form-control" placeholder="文字" style="width:  33.333%;">
                        <span class="input-group-btn" onclick="parameter.parameter_add(this)">
                            <button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button>
                        </span>
                        <span class="input-group-btn" onclick="parameter.parameter_del(this)">
                            <button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button>
                        </span>
                                    </div>
                                    {/loop}
                                    {else}
                                    <div class="input-group param">
                                        <input type="text" name="simg" value="" class="form-control" autocomplete="off">
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="button" onclick="showImageDialog(this);">头像</button>
                        </span>
                                        <input type="text" name="nick" value="" class="form-control" placeholder="昵称" style="width: 33.333%;">
                                        <input type="text" name="number" value="" class="form-control" placeholder="数量" style="width:  33.333%;">
                                        <input type="text" name="content" value="" class="form-control" placeholder="文字" style="width:  33.333%;">
                        <span class="input-group-btn" onclick="parameter.parameter_add(this)">
                            <button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button>
                        </span>
                        <span class="input-group-btn" onclick="parameter.parameter_del(this)">
                            <button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button>
                        </span>
                                    </div>
                                    {/if}
                                </div>
                            </div>
                            <script>
                                var parameter={
                                    parameter_add:function(objc){
                                        $(objc).parent().after('<div class="input-group param">' +
                                                '<input type="text" name="simg" value="" class="form-control" autocomplete="off">' +
                                                '<span class="input-group-btn"> ' +
                                                '<button class="btn btn-default" type="button" onclick="showImageDialog(this);">头像</button> ' +
                                                '</span> ' +
                                                '<input type="text" name="nick" value="" class="form-control" placeholder="昵称" style="width: 33.333%;"> ' +
                                                '<input type="text" name="number" value="" class="form-control" placeholder="数量" style="width:  33.333%;"> ' +
                                                '<input type="text" name="content" value="" class="form-control" placeholder="文字" style="width:  33.333%;"> ' +
                                                '<span class="input-group-btn" onclick="parameter.parameter_add(this)"> ' +
                                                '<button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button> ' +
                                                '</span> ' +
                                                '<span class="input-group-btn" onclick="parameter.parameter_del(this)"> ' +
                                                '<button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button> ' +
                                                '</span> ' +
                                                '</div>')
                                    },
                                    parameter_del:function(objc){
                                        if($(objc).parent().siblings().length>0){
                                            $(objc).parent().remove();
                                        }
                                    }
                                }
                            </script>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">状态</label>
                                <div class="col-sm-8">
                                    <input type="checkbox" class="js-switch" value="1" name="status"
                                           data-value="{$list['status']}" data-field="status">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">排序</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="sort" value="{$list['sort']}">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <input type="button" name="submit" class="btn btn-default" value="提交">
                                    <a type="button" class="btn btn-default"  href="{php echo $this->createWebUrl($do, array('op'=>'list','xtitleb'=> urlencode($xtitleb),'xtitlea'=>urlencode($xtitlea),'new'=>1));}" >返回</a>
                                    <input id="res" name="res" type="reset" style="display:none;" />
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
{template 'common/editfoot'}
<script>
    $(function(){
        $("input[name='submit']").click(function(){
            getJson();
            var data=$(".form-horizontal").serialize();
            $.ajax({
                type:"post",
                url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'savemodel','version_id'=>$_GPC['version_id'])}",
                data:data,
                dataType:'json',
                success:function(res){
                    if(res.status==1){
                        if($("input[name='id']").val()==""){
                            $("input[name='res']").click();
                            $("body").find(".img-responsive.img-thumbnail").attr("src","");
                        }
                        swal('操作成功!', '操作成功!', 'success');
                    }else{
                        swal('操作失败!', '操作失败!', 'error');
                    }
                }
            })
        });
    });

    function getJson(){
        var link=[];
        $("body").find(".param").each(function(){
            var simg=$(this).find("input[name='simg']").val();
            var nick=$(this).find("input[name='nick']").val();
            var number=$(this).find("input[name='number']").val();
            var content=$(this).find("input[name='content']").val();
            if(simg!="" && nick!="" && number!=""){
                var data={simg:simg,nick:nick,number:number,content:content};
                link.push(data);
            }
        });
        if(link.length>0){
            $("input[name='link']").val(JSON.stringify(link));
        }
    }
</script>
</body>
</html>